import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

/**
 * Created by codeczx on 2017/7/18.
 */
public class Client1 {
    public static int count = 0;

    public static void main(String[] args) {
        Socket client = null;
        try {
            client = new Socket("127.0.0.1", 20006);
            count++;
            client.setSoTimeout(10000);
            BufferedReader sIn = new BufferedReader(new InputStreamReader(System.in));
            PrintStream clientOut = new PrintStream(client.getOutputStream());
            BufferedReader clientIn = new BufferedReader(new InputStreamReader(client.getInputStream()));

            boolean flag = true;
            while (flag) {
                System.out.print("count"+count+":");
                String str = sIn.readLine();
                clientOut.println(str);
                if ("bye".equals(str)) {
                    flag = false;
                } else {
                    String echo = clientIn.readLine();
                    System.out.println(echo);
                }
            }
            clientIn.close();
            client.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
